def set_stage():
stage.set_background("soccerfield")
stage.disable_floor()
def main():
""" Sets up the program and calls other functions """
set_stage()
main()
t = codesters.Teacher()
defs = t.find_block("def")
docstrings = t.find_text('"""')
num_docstrings = len(docstrings)
default_doc = '""" This is a description of what this function does """'.replace(' ','').lower()
def above_def(line_number, def_list):
""" Returns the name of the nearest function and the distance above the given line number """
function_name = ""
distance = line_number - def_list[0][0]
for func in def_list:
if line_number - func[0] <= distance and line_number - func[0] > 0:
function_name = func[1]
distance = line_number - func[0]
return function_name, distance
num_docstrings = len(docstrings)
test_strings = ['set', 'up', 'stage'] #'Sets up the stage for the game'
try:
text = docstrings[0][1]
text = text.replace(' ','').lower()
line_number = docstrings[0][0]
indent = t.get_indent_at_line(line_number)
except:
text = "DNE"
line_number == "DNE"
indent = "DNE"
try:
func, distance = above_def(docstrings[0][0], defs)
except:
func = "DNE"
distance = "DNE"
t1 = TestObjective()
t1.add_success(num_docstrings > 1, "Great job!")
t1.add_failure(num_docstrings == 1, "Did you add a Docstring under set_stage()?")
t1.add_failure(num_docstrings == 0, "Oops. Did you delete a docstring?")
t2 = TestObjective()
t2.add_success(text != default_doc and num_docstrings > 1, "Great job!")
t2.add_failure(text == default_doc, "Did you change the docstring to describe the function?")
t2.add_failure(num_docstrings == 1, "Did you add a Docstring under set_stage()?")
t3 = TestObjective()
t3.add_success(indent == 4 and num_docstrings > 1, "Great job!")
t3.add_failure(indent < 4, "Did you indent the docstring inside set_stage()?")
t3.add_failure(indent > 4, "Oops, did you indent the docstring more than once?")
t3.add_failure(indent == "DNE", "Did you indent the docstring inside set_stage()?")
t3.add_failure(num_docstrings == 1, "Did you add a Docstring under set_stage()?")
t4 = TestObjective()
t4.add_success("set_stage" in func and distance < 5, "Great job!")
t4.add_failure("set_stage" not in func, "Did you place the docstring under set_stage()?")
t4.add_failure(distance >= 5, "Make sure the docstring is at the top of the function!")
t4.add_failure(func == "DNE", "Did you delete a docstring?")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Submit Work
-
Next Activity
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)